/*
 * my_camera.h
 *
 *  Created on: Feb 19, 2024
 *      Author: 86138
 */

#ifndef MY_CAMERA_H_
#define MY_CAMERA_H_
#include "zf_common_headfile.h"
#include <stdbool.h> // 为了使用bool类型

#define HEIGHT 120
#define WIDTH 188
#define RESULT_WIDTH 128
#define RESULT_HEIGHT 110

//test
extern uint8_t temp , temp1 ,temp2 , temp3 , temp4 ,temp5 ;


//大津法
extern uint8_t image_threshold[RESULT_HEIGHT][RESULT_WIDTH];
extern uint8_t threshold;
//循迹
extern uint8_t col, row, _row, height, width;

extern uint8_t mode;
extern uint8_t flag1;
extern uint8_t flag2;
extern uint8_t flag_shizi;
extern float seed_delta, seed_delta_ahead;
extern uint8_t seed_left[RESULT_HEIGHT];
extern uint8_t seed_right[RESULT_HEIGHT];
extern uint8_t middle_line[RESULT_HEIGHT];
extern uint8_t middle_line_end;
extern uint8_t garage_out_flag, garage_in_flag;

////丢线
//extern uint8_t zuodiuxian_cnt; // ���м��ζ���
//extern uint8_t zuodiuxian_flag ;
//extern uint8_t zuodiuxian[HEIGHT] ;
//extern uint8_t zuodiuxian_start[HEIGHT] ;
//
//extern uint8_t youdiuxian_cnt ; // ���м��ζ���
//extern uint8_t youdiuxian_flag ;
//extern uint8_t youdiuxian[HEIGHT] ;
//extern uint8_t youdiuxian_start[HEIGHT];

//turningpoint
extern uint8_t leftTurningpoint[HEIGHT][2]; // ����ÿ�ζ��߶��˶���
extern uint8_t rightTurningpoint[HEIGHT][2]; // ����ÿ�ζ��߶��˶���

extern uint8_t left_tp_cnt;
extern uint8_t right_tp_cnt;
extern uint8_t tp_r;
extern uint8_t tp_l;
//left
extern int8_t turningpoint_operator[7]; //注意這個數組需要有符號！！！
extern int16_t operator_result_left[RESULT_HEIGHT];
extern uint8_t minima_left[2];
extern uint8_t indices_left[2];
extern bool foundFirstNonzero_left;
extern uint8_t operator_count_left;
extern uint8_t operator_count_flag_left;
//right
extern int16_t operator_result_right[RESULT_HEIGHT];
extern uint8_t minima_right[2];
extern uint8_t indices_right[2];
extern bool foundFirstNonzero_right;
extern uint8_t operator_count_right;
extern uint8_t operator_count_flag_right;

extern uint8_t operator_left_max;
extern uint8_t operator_left_min;
extern uint8_t operator_right_max;
extern uint8_t operator_right_min;

extern uint8_t proximityThreshold;

//rightcircle
extern double deg_circle;
extern double deg_in;
extern uint8_t straight_left;
extern uint8_t straight_right;
extern uint8_t circle_before;
extern uint8_t circle_in;
extern uint8_t circle_at;
extern uint8_t circle_out;
extern uint8_t circle_right_flag;
extern uint8_t circle_left_flag;

//里程计
extern double road;
//最长白列
extern uint8_t length[RESULT_WIDTH];
extern uint8_t longest;
extern uint8_t _longest;
extern uint8_t white_col;

//crossroads
void crossroads(void);
extern uint8_t crossroads_flag;

//拉线  conect_line_branch
extern uint8_t conect_line_flag;
extern uint8_t conect_line_flag_left;
extern uint8_t conect_line_flag_right;

//斑马线
extern uint8_t garage_out_flag, garage_in_flag;
extern double garage_road ;


//障碍
extern uint8_t barrier_flag ;
extern uint8_t barrier_cnt ;
extern double barrier_start ;

void adapt_threshold(void);
uint8_t PerImg_threshold(uint8_t i, uint8_t j);
void detect_seed(uint8_t _height);
void calculateOperatorResult(uint8_t y, uint8_t state);
void turning_point(void);
void circle(uint8_t _height);
void conect_line_branch(void);
void garage(void);
void delta(void);
void circle_right(void);
void circle_left(void);
void escape_barrier(void);


#endif /* MY_CAMERA_H_ */
